{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名 陈冲 \n",
    "+ 学号 0160908"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "淋雨一直走-张韶涵\n",
      "Oh\n",
      "人都应该有梦\n",
      "有梦就别怕痛\n",
      "有雷声在轰不停\n",
      "雨泼进眼里看不清\n",
      "谁急速狂飙\n",
      "溅我一身\n",
      "的泥泞\n",
      "我决定我想去哪里\n",
      "往天堂要跳过地狱\n",
      "也不恐惧\n",
      "不逃避\n",
      "这不是脾气\n",
      "是所谓志气\n",
      "与勇气\n",
      "你能推我下悬崖\n",
      "我能学会飞行\n",
      "从不听\n",
      "谁的命令\n",
      "很独立\n",
      "耳朵用来听自己的心灵\n",
      "淋雨一直走\n",
      "是一颗宝石就该闪烁\n",
      "人都应该有梦\n",
      "Oh\n",
      "有梦就别怕痛\n",
      "淋雨一直走\n",
      "是道阳光就该暖和\n",
      "人都应该有梦\n",
      "Oh\n",
      "有梦就别怕痛\n",
      "淋雨一直走\n",
      "是一颗宝石就该闪烁\n",
      "人都应该有梦\n",
      "Oh\n",
      "有梦就别怕痛\n",
      "淋雨一直走\n",
      "是道阳光就该暖和\n",
      "人都应该有梦\n",
      "Oh\n",
      "有梦就别怕痛\n"
     ]
    }
   ],
   "source": [
    "print(\"淋雨一直走-张韶涵\")\n",
    "def verse():\n",
    "    print(\"Oh\\n人都应该有梦\\n有梦就别怕痛\\n有雷声在轰不停\\n雨泼进眼里看不清\\n谁急速狂飙\\n溅我一身\\n的泥泞\\n我决定我想去哪里\\n往天堂要跳过地狱\\n也不恐惧\\n不逃避\\n这不是脾气\\n是所谓志气\\n与勇气\\n你能推我下悬崖\\n我能学会飞行\\n从不听\\n谁的命令\\n很独立\\n耳朵用来听自己的心灵\")\n",
    "verse() \n",
    "def chorus():\n",
    "    print(\"淋雨一直走\\n是一颗宝石就该闪烁\\n人都应该有梦\\nOh\\n有梦就别怕痛\\n淋雨一直走\\n是道阳光就该暖和\\n人都应该有梦\\nOh\\n有梦就别怕痛\")\n",
    "chorus()\n",
    "chorus()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "有10个数\n",
      "均值为6.80\n",
      "样本方差为27.36\n",
      "有11个数\n",
      "均值为54.55\n",
      "样本方差为1086.07\n"
     ]
    }
   ],
   "source": [
    "def hanshu(*shuzi):\n",
    "    junzhi=0\n",
    "    fangcha=0\n",
    "    fangchahe=0\n",
    "    i=0\n",
    "    he=0\n",
    "    for value in shuzi:\n",
    "        he=he+value\n",
    "        i=i+1\n",
    "    junzhi=he/i\n",
    "    print('有%s个数'%i)\n",
    "    print('均值为%.2f'%junzhi)\n",
    "    for value in shuzi:\n",
    "        fangchahe=fangchahe+(value-junzhi)**2\n",
    "    fangcha=fangchahe/i\n",
    "    print('样本方差为%.2f'%fangcha)\n",
    "hanshu(1,2,3,4,5,6,10,8,9,20)\n",
    "hanshu(0,11,21,53,74,52,66,37,86,99,101)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def hanshu(*shuzi):\n",
    "    junzhi=0\n",
    "    fangcha=0\n",
    "    fangchahe=0\n",
    "    i=0\n",
    "    he=0\n",
    "    for value in shuzi:\n",
    "        he=he+value\n",
    "        i=i+1\n",
    "    junzhi=he/i\n",
    "    print('有%s个数'%i)\n",
    "    print('均值为%.2f'%junzhi)\n",
    "    for value in shuzi:\n",
    "        fangchahe=fangchahe+(value-junzhi)**2\n",
    "    fangcha=fangchahe/i\n",
    "    biaozhuncha=fangcha**(1/2)\n",
    "    print(\"方差请按1，标准差请按2\")\n",
    "    xuanze=int(input())\n",
    "    if xuanze==1:\n",
    "        print('样本方差为%.2f\\n'%fangcha)\n",
    "    if xuanze==2:\n",
    "        print('标准差为%.2f\\n'%biaozhuncha)\n",
    "hanshu(0,1,2,3,4,5,6,7,8,9)\n",
    "hanshu(0,11,21,53,74,52,66,37,86,99,101)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "有10个数\n",
      "均值为4.50\n",
      "方差请按1，标准差请按2\n"
     ]
    }
   ],
   "source": [
    "def hanshu(*shuzi):\n",
    "    junzhi=0\n",
    "    fangcha=0\n",
    "    fangchahe=0\n",
    "    i=0\n",
    "    he=0\n",
    "    pingfanghe=0\n",
    "    for value in shuzi:\n",
    "        he=he+value\n",
    "        i=i+1\n",
    "    junzhi=he/i\n",
    "    print('有%s个数'%i)\n",
    "    print('均值为%.2f'%junzhi)\n",
    "    for value in shuzi:\n",
    "        fangchahe=fangchahe+(value-junzhi)**2\n",
    "        pingfanghe=pingfanghe+value**2\n",
    "    fangcha=fangchahe/i\n",
    "    biaozhuncha=fangcha**(1/2)#求标准差\n",
    "    biaozhunwu=((pingfanghe/i-junzhi**2)*i/(i-1))/(i**(1/2))#求标准误\n",
    "    print(\"方差请按1，标准差请按2\")\n",
    "    xuanze=int(input())\n",
    "    if xuanze==1:\n",
    "        print('样本方差为%.2f\\n'%fangcha)\n",
    "    if xuanze==2:\n",
    "        print('标准差为%.2f\\n'%biaozhuncha)\n",
    "    \n",
    "    print(\"输出均值的标准误请按1，输出最大值请按2，输出最小值请按3，按0不输出\")\n",
    "    xuanze=int(input())\n",
    "    if xuanze==1:\n",
    "        print('均值的标准误为%.2f\\n'%biaozhunwu)\n",
    "    if xuanze==2:\n",
    "        print('均值的最大值为%.2f\\n'%max(shuzi))\n",
    "    if xuanze==3:\n",
    "        print('均值的最小值为%.2f\\n'%min(shuzi))\n",
    "    if xuanze==0:\n",
    "        print(\"nothing\\n\")\n",
    "hanshu(0,1,2,3,4,5,6,7,8,9)\n",
    "hanshu(0,11,21,53,74,52,66,37,86,99,101)\n",
    "hanshu(0,11,21,53,99,101)\n",
    "hanshu(1,2,3,4,8,9)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
